<%--
  Created by IntelliJ IDEA.
  User: cxy
  Date: 2018-06-14
  Time: 9:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div id="MyModal" class="modal fade" tabindex="-1" role="dialog" >
    <div class="modal-dialog" role="document"style="width: 1200px">
        <div class="modal-content">
            <form action="" method="post" id="Addschedule">                <!--form 表单-->
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">选择药品</h4>
                </div>
                <div class="modal-body">
                    <div class="form-inline">
                        <label for="MName">药品名称:</label>
                        <input id="MName" type="text" class="form-control">
                        <button type="button" onclick="search()" class="btn btn-primary">搜索</button>
                    </div>
                    <table id="table"></table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
                    <button type="button" onclick="Submit()" class="btn btn-primary">提交</button>
                </div>
            </form>                     <!--form 结束-->
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

</body>
<script type="text/javascript">
    function search() {
        var opts = $("#table").bootstrapTable('getOptions');
        var Mname=$("#MName").val();
        $.ajax({
            "url": "${pageContext.request.contextPath}/goods/queryPage",
            "type": "post",
            "data": {
                "mName": Mname,
                "pageNumber": opts.pageNumber,
                "pageSize": opts.pageSize
            },
            "dataType": "json",
            "success": function (data) {
                $("#table").bootstrapTable('load', data);
            }
        })
    }




    $("#table").bootstrapTable({
        url:"${pageContext.request.contextPath}/goods/queryPage",
        undefinedText:"1",
        columns:[{
            checkbox:true
        },{
            title:"药品编号",
            field:"medicineid"
        },{
            title:"药品名称",
            field:"mName"
        },{
            title:"药品单价",
            field:"mPrice"
        },{
            title:"药品规格",
            field:"spec"
        },{
            title:"药品剂型",
            field:"dosageform",
            formatter:function (value,row,index) {
                return "/"+row.dosageform;
            }
        },{
            title:"药品有效期",
            field:"termofvalidity"
        },{
            title:"药品数量",
            field:"mNbumber"
        },{
            title:"拿取数量",
            editable: {
                title:"拿取数量",
                type: "text",
                placement: "left",
                validate(v) {
                    var sele= $("#table").bootstrapTable('getSelections');
                    var test=/^\d*$/;
                    if(test.test(v)==false){
                        return "请输入正确的数量";
                    }
                    if(v>sele.nbumber){
                        return "输入数量不能大于已有数量";
                    }

                }
            }
        }],
        clickToSelect:true,
        editable:true,
        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        height: 500,
        pageList: [5, 10, 15],
        pageSize: 5,
        sortable: true,
        sortOrder: "asc",
        pageNumber: 1,
        pagination: true,
        queryParamsType: '',
        queryParams: queryParams,
        sidePagination: 'server'
    })
    function queryParams(params) {
        var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            pageSize: params.pageSize,  //页面大小
            pageNumber: params.pageNumber, //页码
            mName: $("#MName").val()
        };
        return temp;
    }







</script>
</html>
